package servlet;

import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.db.conn;

public class ptype_Add extends HttpServlet {

	
	public ptype_Add() {
		super();
	}


	public void destroy() {
		super.destroy(); 
	}

	//添加商品分类信息
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;");
		PrintWriter out = response.getWriter();

         //声明数据库操作类
		conn cn = new conn();
	
	    //接收传递过来的值
        String tname=request.getParameter("txt_tname");
		
		
        String sql="insert into ptype(tname) values('"+tname+"')";
        
		


        //验证是否已经存在
        if (cn.exist("select * from ptype where tname = '" + tname + "'"))
        {
            out.println("<script>");
            out.println("alert('该分类名称已存在！');window.history.go(-1);");
            out.println("</script>");
            return ;
        }

   	
		//执行sql
		cn.update(sql);		

		out.println("<script>");
		out.println("alert('操作成功');");
		out.println("window.location='admin/ptype/ptype_Add.jsp'");
		out.println("</script>");
	
		out.flush();
		out.close();
	}


	public void init() throws ServletException {
		// Put your code here
	}

}

